<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>dlaed2.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="DLAED2.1"></a><a href="dlaed2.f.html#DLAED2.1">DLAED2</a>( K, N, N1, D, Q, LDQ, INDXQ, RHO, Z, DLAMDA, W,
     $                   Q2, INDX, INDXC, INDXP, COLTYP, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      INTEGER            INFO, K, LDQ, N, N1
      DOUBLE PRECISION   RHO
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      INTEGER            COLTYP( * ), INDX( * ), INDXC( * ), INDXP( * ),
     $                   INDXQ( * )
      DOUBLE PRECISION   D( * ), DLAMDA( * ), Q( LDQ, * ), Q2( * ),
     $                   W( * ), Z( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="DLAED2.22"></a><a href="dlaed2.f.html#DLAED2.1">DLAED2</a> merges the two sets of eigenvalues together into a single
</span><span class="comment">*</span><span class="comment">  sorted set.  Then it tries to deflate the size of the problem.
</span><span class="comment">*</span><span class="comment">  There are two ways in which deflation can occur:  when two or more
</span><span class="comment">*</span><span class="comment">  eigenvalues are close together or if there is a tiny entry in the
</span><span class="comment">*</span><span class="comment">  Z vector.  For each such occurrence the order of the related secular
</span><span class="comment">*</span><span class="comment">  equation problem is reduced by one.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  K      (output) INTEGER
</span><span class="comment">*</span><span class="comment">         The number of non-deflated eigenvalues, and the order of the
</span><span class="comment">*</span><span class="comment">         related secular equation. 0 &lt;= K &lt;=N.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N      (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The dimension of the symmetric tridiagonal matrix.  N &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N1     (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The location of the last eigenvalue in the leading sub-matrix.
</span><span class="comment">*</span><span class="comment">         min(1,N) &lt;= N1 &lt;= N/2.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  D      (input/output) DOUBLE PRECISION array, dimension (N)
</span><span class="comment">*</span><span class="comment">         On entry, D contains the eigenvalues of the two submatrices to
</span><span class="comment">*</span><span class="comment">         be combined.
</span><span class="comment">*</span><span class="comment">         On exit, D contains the trailing (N-K) updated eigenvalues
</span><span class="comment">*</span><span class="comment">         (those which were deflated) sorted into increasing order.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Q      (input/output) DOUBLE PRECISION array, dimension (LDQ, N)
</span><span class="comment">*</span><span class="comment">         On entry, Q contains the eigenvectors of two submatrices in
</span><span class="comment">*</span><span class="comment">         the two square blocks with corners at (1,1), (N1,N1)
</span><span class="comment">*</span><span class="comment">         and (N1+1, N1+1), (N,N).
</span><span class="comment">*</span><span class="comment">         On exit, Q contains the trailing (N-K) updated eigenvectors
</span><span class="comment">*</span><span class="comment">         (those which were deflated) in its last N-K columns.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDQ    (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The leading dimension of the array Q.  LDQ &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INDXQ  (input/output) INTEGER array, dimension (N)
</span><span class="comment">*</span><span class="comment">         The permutation which separately sorts the two sub-problems
</span><span class="comment">*</span><span class="comment">         in D into ascending order.  Note that elements in the second
</span><span class="comment">*</span><span class="comment">         half of this permutation must first have N1 added to their
</span><span class="comment">*</span><span class="comment">         values. Destroyed on exit.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  RHO    (input/output) DOUBLE PRECISION
</span><span class="comment">*</span><span class="comment">         On entry, the off-diagonal element associated with the rank-1
</span><span class="comment">*</span><span class="comment">         cut which originally split the two submatrices which are now
</span><span class="comment">*</span><span class="comment">         being recombined.
</span><span class="comment">*</span><span class="comment">         On exit, RHO has been modified to the value required by
</span><span class="comment">*</span><span class="comment">         <a name="DLAED3.70"></a><a href="dlaed3.f.html#DLAED3.1">DLAED3</a>.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Z      (input) DOUBLE PRECISION array, dimension (N)
</span><span class="comment">*</span><span class="comment">         On entry, Z contains the updating vector (the last
</span><span class="comment">*</span><span class="comment">         row of the first sub-eigenvector matrix and the first row of
</span><span class="comment">*</span><span class="comment">         the second sub-eigenvector matrix).
</span><span class="comment">*</span><span class="comment">         On exit, the contents of Z have been destroyed by the updating
</span><span class="comment">*</span><span class="comment">         process.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  DLAMDA (output) DOUBLE PRECISION array, dimension (N)
</span><span class="comment">*</span><span class="comment">         A copy of the first K eigenvalues which will be used by
</span><span class="comment">*</span><span class="comment">         <a name="DLAED3.81"></a><a href="dlaed3.f.html#DLAED3.1">DLAED3</a> to form the secular equation.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  W      (output) DOUBLE PRECISION array, dimension (N)
</span><span class="comment">*</span><span class="comment">         The first k values of the final deflation-altered z-vector
</span><span class="comment">*</span><span class="comment">         which will be passed to <a name="DLAED3.85"></a><a href="dlaed3.f.html#DLAED3.1">DLAED3</a>.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Q2     (output) DOUBLE PRECISION array, dimension (N1**2+(N-N1)**2)
</span><span class="comment">*</span><span class="comment">         A copy of the first K eigenvectors which will be used by
</span><span class="comment">*</span><span class="comment">         <a name="DLAED3.89"></a><a href="dlaed3.f.html#DLAED3.1">DLAED3</a> in a matrix multiply (DGEMM) to solve for the new
</span><span class="comment">*</span><span class="comment">         eigenvectors.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INDX   (workspace) INTEGER array, dimension (N)
</span><span class="comment">*</span><span class="comment">         The permutation used to sort the contents of DLAMDA into
</span><span class="comment">*</span><span class="comment">         ascending order.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INDXC  (output) INTEGER array, dimension (N)
</span><span class="comment">*</span><span class="comment">         The permutation used to arrange the columns of the deflated
</span><span class="comment">*</span><span class="comment">         Q matrix into three groups:  the first group contains non-zero
</span><span class="comment">*</span><span class="comment">         elements only at and above N1, the second contains
</span><span class="comment">*</span><span class="comment">         non-zero elements only below N1, and the third is dense.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INDXP  (workspace) INTEGER array, dimension (N)
</span><span class="comment">*</span><span class="comment">         The permutation used to place deflated values of D at the end
</span><span class="comment">*</span><span class="comment">         of the array.  INDXP(1:K) points to the nondeflated D-values
</span><span class="comment">*</span><span class="comment">         and INDXP(K+1:N) points to the deflated eigenvalues.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  COLTYP (workspace/output) INTEGER array, dimension (N)
</span><span class="comment">*</span><span class="comment">         During execution, a label which will indicate which of the
</span><span class="comment">*</span><span class="comment">         following types a column in the Q2 matrix is:
</span><span class="comment">*</span><span class="comment">         1 : non-zero in the upper half only;
</span><span class="comment">*</span><span class="comment">         2 : dense;
</span><span class="comment">*</span><span class="comment">         3 : non-zero in the lower half only;
</span><span class="comment">*</span><span class="comment">         4 : deflated.
</span><span class="comment">*</span><span class="comment">         On exit, COLTYP(i) is the number of columns of type i,
</span><span class="comment">*</span><span class="comment">         for i=1 to 4 only.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO   (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit.
</span><span class="comment">*</span><span class="comment">          &lt; 0:  if INFO = -i, the i-th argument had an illegal value.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Based on contributions by
</span><span class="comment">*</span><span class="comment">     Jeff Rutter, Computer Science Division, University of California
</span><span class="comment">*</span><span class="comment">     at Berkeley, USA
</span><span class="comment">*</span><span class="comment">  Modified by Francoise Tisseur, University of Tennessee.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      DOUBLE PRECISION   MONE, ZERO, ONE, TWO, EIGHT
      PARAMETER          ( MONE = -1.0D0, ZERO = 0.0D0, ONE = 1.0D0,
     $                   TWO = 2.0D0, EIGHT = 8.0D0 )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Arrays ..
</span>      INTEGER            CTOT( 4 ), PSM( 4 )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      INTEGER            CT, I, IMAX, IQ1, IQ2, J, JMAX, JS, K2, N1P1,
     $                   N2, NJ, PJ
      DOUBLE PRECISION   C, EPS, S, T, TAU, TOL
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      INTEGER            IDAMAX
      DOUBLE PRECISION   <a name="DLAMCH.146"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>, <a name="DLAPY2.146"></a><a href="dlapy2.f.html#DLAPY2.1">DLAPY2</a>
      EXTERNAL           IDAMAX, <a name="DLAMCH.147"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>, <a name="DLAPY2.147"></a><a href="dlapy2.f.html#DLAPY2.1">DLAPY2</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           DCOPY, <a name="DLACPY.150"></a><a href="dlacpy.f.html#DLACPY.1">DLACPY</a>, <a name="DLAMRG.150"></a><a href="dlamrg.f.html#DLAMRG.1">DLAMRG</a>, DROT, DSCAL, <a name="XERBLA.150"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          ABS, MAX, MIN, SQRT
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input parameters.
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
<span class="comment">*</span><span class="comment">
</span>      IF( N.LT.0 ) THEN
         INFO = -2
      ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN
         INFO = -6
      ELSE IF( MIN( 1, ( N / 2 ) ).GT.N1 .OR. ( N / 2 ).LT.N1 ) THEN
         INFO = -3
      END IF
      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.169"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="DLAED2.169"></a><a href="dlaed2.f.html#DLAED2.1">DLAED2</a>'</span>, -INFO )
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Quick return if possible
</span><span class="comment">*</span><span class="comment">
</span>      IF( N.EQ.0 )
     $   RETURN
<span class="comment">*</span><span class="comment">
</span>      N2 = N - N1
      N1P1 = N1 + 1
<span class="comment">*</span><span class="comment">
</span>      IF( RHO.LT.ZERO ) THEN
         CALL DSCAL( N2, MONE, Z( N1P1 ), 1 )
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Normalize z so that norm(z) = 1.  Since z is the concatenation of
</span><span class="comment">*</span><span class="comment">     two normalized vectors, norm2(z) = sqrt(2).
</span><span class="comment">*</span><span class="comment">
</span>      T = ONE / SQRT( TWO )
      CALL DSCAL( N, T, Z, 1 )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     RHO = ABS( norm(z)**2 * RHO )
</span><span class="comment">*</span><span class="comment">
</span>      RHO = ABS( TWO*RHO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Sort the eigenvalues into increasing order
</span><span class="comment">*</span><span class="comment">
</span>      DO 10 I = N1P1, N
         INDXQ( I ) = INDXQ( I ) + N1
   10 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     re-integrate the deflated parts from the last pass
</span><span class="comment">*</span><span class="comment">
</span>      DO 20 I = 1, N
         DLAMDA( I ) = D( INDXQ( I ) )
   20 CONTINUE
      CALL <a name="DLAMRG.206"></a><a href="dlamrg.f.html#DLAMRG.1">DLAMRG</a>( N1, N2, DLAMDA, 1, 1, INDXC )
      DO 30 I = 1, N
         INDX( I ) = INDXQ( INDXC( I ) )
   30 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Calculate the allowable deflation tolerance
</span><span class="comment">*</span><span class="comment">
</span>      IMAX = IDAMAX( N, Z, 1 )
      JMAX = IDAMAX( N, D, 1 )
      EPS = <a name="DLAMCH.215"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>( <span class="string">'Epsilon'</span> )
      TOL = EIGHT*EPS*MAX( ABS( D( JMAX ) ), ABS( Z( IMAX ) ) )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     If the rank-1 modifier is small enough, no more needs to be done
</span><span class="comment">*</span><span class="comment">     except to reorganize Q so that its columns correspond with the
</span><span class="comment">*</span><span class="comment">     elements in D.
</span><span class="comment">*</span><span class="comment">
</span>      IF( RHO*ABS( Z( IMAX ) ).LE.TOL ) THEN
         K = 0
         IQ2 = 1
         DO 40 J = 1, N
            I = INDX( J )
            CALL DCOPY( N, Q( 1, I ), 1, Q2( IQ2 ), 1 )
            DLAMDA( J ) = D( I )
            IQ2 = IQ2 + N
   40    CONTINUE
         CALL <a name="DLACPY.231"></a><a href="dlacpy.f.html#DLACPY.1">DLACPY</a>( <span class="string">'A'</span>, N, N, Q2, N, Q, LDQ )
         CALL DCOPY( N, DLAMDA, 1, D, 1 )
         GO TO 190
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     If there are multiple eigenvalues then the problem deflates.  Here
</span><span class="comment">*</span><span class="comment">     the number of equal eigenvalues are found.  As each equal
</span><span class="comment">*</span><span class="comment">     eigenvalue is found, an elementary reflector is computed to rotate
</span><span class="comment">*</span><span class="comment">     the corresponding eigensubspace so that the corresponding
</span><span class="comment">*</span><span class="comment">     components of Z are zero in this new basis.
</span><span class="comment">*</span><span class="comment">
</span>      DO 50 I = 1, N1
         COLTYP( I ) = 1
   50 CONTINUE
      DO 60 I = N1P1, N
         COLTYP( I ) = 3
   60 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">
</span>      K = 0
      K2 = N + 1
      DO 70 J = 1, N
         NJ = INDX( J )
         IF( RHO*ABS( Z( NJ ) ).LE.TOL ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Deflate due to small z component.
</span><span class="comment">*</span><span class="comment">
</span>            K2 = K2 - 1
            COLTYP( NJ ) = 4
            INDXP( K2 ) = NJ
            IF( J.EQ.N )
     $         GO TO 100
         ELSE
            PJ = NJ
            GO TO 80
         END IF
   70 CONTINUE
   80 CONTINUE
      J = J + 1
      NJ = INDX( J )
      IF( J.GT.N )
     $   GO TO 100
      IF( RHO*ABS( Z( NJ ) ).LE.TOL ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Deflate due to small z component.
</span><span class="comment">*</span><span class="comment">
</span>         K2 = K2 - 1
         COLTYP( NJ ) = 4
         INDXP( K2 ) = NJ
      ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Check if eigenvalues are close enough to allow deflation.
</span><span class="comment">*</span><span class="comment">
</span>         S = Z( PJ )
         C = Z( NJ )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Find sqrt(a**2+b**2) without overflow or
</span><span class="comment">*</span><span class="comment">        destructive underflow.
</span><span class="comment">*</span><span class="comment">
</span>         TAU = <a name="DLAPY2.290"></a><a href="dlapy2.f.html#DLAPY2.1">DLAPY2</a>( C, S )
         T = D( NJ ) - D( PJ )
         C = C / TAU
         S = -S / TAU
         IF( ABS( T*C*S ).LE.TOL ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Deflation is possible.
</span><span class="comment">*</span><span class="comment">
</span>            Z( NJ ) = TAU
            Z( PJ ) = ZERO
            IF( COLTYP( NJ ).NE.COLTYP( PJ ) )
     $         COLTYP( NJ ) = 2
            COLTYP( PJ ) = 4
            CALL DROT( N, Q( 1, PJ ), 1, Q( 1, NJ ), 1, C, S )
            T = D( PJ )*C**2 + D( NJ )*S**2
            D( NJ ) = D( PJ )*S**2 + D( NJ )*C**2
            D( PJ ) = T
            K2 = K2 - 1
            I = 1
   90       CONTINUE
            IF( K2+I.LE.N ) THEN
               IF( D( PJ ).LT.D( INDXP( K2+I ) ) ) THEN
                  INDXP( K2+I-1 ) = INDXP( K2+I )
                  INDXP( K2+I ) = PJ
                  I = I + 1
                  GO TO 90
               ELSE
                  INDXP( K2+I-1 ) = PJ
               END IF
            ELSE
               INDXP( K2+I-1 ) = PJ
            END IF
            PJ = NJ
         ELSE
            K = K + 1
            DLAMDA( K ) = D( PJ )
            W( K ) = Z( PJ )
            INDXP( K ) = PJ
            PJ = NJ
         END IF
      END IF
      GO TO 80
  100 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Record the last eigenvalue.
</span><span class="comment">*</span><span class="comment">
</span>      K = K + 1
      DLAMDA( K ) = D( PJ )
      W( K ) = Z( PJ )
      INDXP( K ) = PJ
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Count up the total number of the various types of columns, then
</span><span class="comment">*</span><span class="comment">     form a permutation which positions the four column types into
</span><span class="comment">*</span><span class="comment">     four uniform groups (although one or more of these groups may be
</span><span class="comment">*</span><span class="comment">     empty).
</span><span class="comment">*</span><span class="comment">
</span>      DO 110 J = 1, 4
         CTOT( J ) = 0
  110 CONTINUE
      DO 120 J = 1, N
         CT = COLTYP( J )
         CTOT( CT ) = CTOT( CT ) + 1
  120 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     PSM(*) = Position in SubMatrix (of types 1 through 4)
</span><span class="comment">*</span><span class="comment">
</span>      PSM( 1 ) = 1
      PSM( 2 ) = 1 + CTOT( 1 )
      PSM( 3 ) = PSM( 2 ) + CTOT( 2 )
      PSM( 4 ) = PSM( 3 ) + CTOT( 3 )
      K = N - CTOT( 4 )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Fill out the INDXC array so that the permutation which it induces
</span><span class="comment">*</span><span class="comment">     will place all type-1 columns first, all type-2 columns next,
</span><span class="comment">*</span><span class="comment">     then all type-3's, and finally all type-4's.
</span><span class="comment">*</span><span class="comment">
</span>      DO 130 J = 1, N
         JS = INDXP( J )
         CT = COLTYP( JS )
         INDX( PSM( CT ) ) = JS
         INDXC( PSM( CT ) ) = J
         PSM( CT ) = PSM( CT ) + 1
  130 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Sort the eigenvalues and corresponding eigenvectors into DLAMDA
</span><span class="comment">*</span><span class="comment">     and Q2 respectively.  The eigenvalues/vectors which were not
</span><span class="comment">*</span><span class="comment">     deflated go into the first K slots of DLAMDA and Q2 respectively,
</span><span class="comment">*</span><span class="comment">     while those which were deflated go into the last N - K slots.
</span><span class="comment">*</span><span class="comment">
</span>      I = 1
      IQ1 = 1
      IQ2 = 1 + ( CTOT( 1 )+CTOT( 2 ) )*N1
      DO 140 J = 1, CTOT( 1 )
         JS = INDX( I )
         CALL DCOPY( N1, Q( 1, JS ), 1, Q2( IQ1 ), 1 )
         Z( I ) = D( JS )
         I = I + 1
         IQ1 = IQ1 + N1
  140 CONTINUE
<span class="comment">*</span><span class="comment">
</span>      DO 150 J = 1, CTOT( 2 )
         JS = INDX( I )
         CALL DCOPY( N1, Q( 1, JS ), 1, Q2( IQ1 ), 1 )
         CALL DCOPY( N2, Q( N1+1, JS ), 1, Q2( IQ2 ), 1 )
         Z( I ) = D( JS )
         I = I + 1
         IQ1 = IQ1 + N1
         IQ2 = IQ2 + N2
  150 CONTINUE
<span class="comment">*</span><span class="comment">
</span>      DO 160 J = 1, CTOT( 3 )
         JS = INDX( I )
         CALL DCOPY( N2, Q( N1+1, JS ), 1, Q2( IQ2 ), 1 )
         Z( I ) = D( JS )
         I = I + 1
         IQ2 = IQ2 + N2
  160 CONTINUE
<span class="comment">*</span><span class="comment">
</span>      IQ1 = IQ2
      DO 170 J = 1, CTOT( 4 )
         JS = INDX( I )
         CALL DCOPY( N, Q( 1, JS ), 1, Q2( IQ2 ), 1 )
         IQ2 = IQ2 + N
         Z( I ) = D( JS )
         I = I + 1
  170 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     The deflated eigenvalues and their corresponding vectors go back
</span><span class="comment">*</span><span class="comment">     into the last N - K slots of D and Q respectively.
</span><span class="comment">*</span><span class="comment">
</span>      CALL <a name="DLACPY.420"></a><a href="dlacpy.f.html#DLACPY.1">DLACPY</a>( <span class="string">'A'</span>, N, CTOT( 4 ), Q2( IQ1 ), N, Q( 1, K+1 ), LDQ )
      CALL DCOPY( N-K, Z( K+1 ), 1, D( K+1 ), 1 )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Copy CTOT into COLTYP for referencing in <a name="DLAED3.423"></a><a href="dlaed3.f.html#DLAED3.1">DLAED3</a>.
</span><span class="comment">*</span><span class="comment">
</span>      DO 180 J = 1, 4
         COLTYP( J ) = CTOT( J )
  180 CONTINUE
<span class="comment">*</span><span class="comment">
</span>  190 CONTINUE
      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="DLAED2.432"></a><a href="dlaed2.f.html#DLAED2.1">DLAED2</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
